package cn.pku.eecs.ldn.tool;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Matrix;
import android.util.Log;

public class Test {

	public static void testMatrix() {
		Matrix matrix = new Matrix();
	}

	public static void testJSON() {
		JSONObject jsonObjectOrigin = new JSONObject();
		try {
			jsonObjectOrigin.put("name", "John Doe");
			jsonObjectOrigin.put("ageInt", Integer.valueOf(25));
			jsonObjectOrigin.put("ageString", "25");
			jsonObjectOrigin.put("address",
					"75 Ninth Avenue 2nd and 4th Floors New York, NY 10011");
			jsonObjectOrigin.put("phone", "8367667829");
			JSONArray jsonArray = new JSONArray();
			jsonArray.put(1);
			jsonArray.put(2);
			jsonArray.put("true");
			jsonArray.put(0.12345);
			jsonObjectOrigin.put("jsonArray", jsonArray);
		} catch (JSONException e) {
			e.printStackTrace();
		}

		String jsonString = jsonObjectOrigin.toString();
		Log.d("testJSON", "testJSON(): jsonString " + jsonString);
		try {
			JSONObject jsonObjectParsed = new JSONObject(jsonString);
			String name = jsonObjectParsed.getString("name");
			String ageString = jsonObjectParsed.getString("ageString");
			int ageInt = jsonObjectParsed.getInt("ageInt");
			String address = jsonObjectParsed.getString("address");
			String phone = jsonObjectParsed.getString("phone");
			JSONArray jsonArray = jsonObjectParsed.getJSONArray("jsonArray");
			boolean bool = jsonArray.getBoolean(2);
			String boolString = jsonArray.getString(2);
			Log.d("testJSON", "testJSON(): " + name);
			Log.d("testJSON", "testJSON(): " + ageInt);
			Log.d("testJSON", "testJSON(): " + ageString);
			Log.d("testJSON", "testJSON(): " + address);
			Log.d("testJSON", "testJSON(): " + phone);
			Log.d("testJSON", "testJSON(): " + jsonArray.toString());
			Log.d("testJSON", "testJSON(): " + bool);
			Log.d("testJSON", "testJSON(): " + boolString);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}
